[#ftl]
[#--include "../../util.ftl"/--]

[#include "MenuItem.ftl"/]
[@define "agile.dijit.Menu" "agile._Component,agile._Container,agile._Resizable,agile._ContainerToolbar"]
	widgetName:"Menu"
	[#assign templateString][#compress]
		<div class='agileComponent agileMenu'>
			<div data-dojo-type='dijit.InlineEditBox' data-dojo-attach-point='accelKey' style='display:none'>{parameters.accelKey}</div>
			<div style="height:100%;width:{style.width};background-color:#e6e6fa" data-dojo-attach-point="containerNode"></div>			
		</div>
	[/#compress][/#assign]
	,templateString:"${templateString?js_string}"
	,sortAxis:"y"	
	,resizeAxis:"y"
	,autoAdjustChildren:true
	,styleConstraints:agile.delegate(agile._Component.prototype.styleConstraints,{
		"left": {ignore:function(widget,sourceType){ return widget.metadata("isSubMenu");}
				,readOnly:function(widget,sourceType){return widget.metadata("isSubMenu");}}
		,"top": {ignore:function(widget,sourceType){ return widget.metadata("isSubMenu");}
				,readOnly:function(widget,sourceType){return widget.metadata("isSubMenu");}}
	    ,"height":{ignore:function(widget,sourceType){return sourceType !="agile";}}
	    ,"width":{_readOnly:true,ignore:function(widget,sourceType){return sourceType !="agile";}}
	    ,"position":{ignore:function(widget,sourceType){return widget.metadata("isSubMenu");}}
	    ,"z-index":{_ignore:true}
	})
	,attributes:agile.delegate(agile._Component.prototype.attributes,{
		contextMenuForWindow:lang.mixin({},agile.BooleanMetadata,{
			label:"i18n_context_menu"
			,hidden:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,ignore:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
		})
		,targetNodeIds:lang.mixin({},agile.ArrayMetadata,{
			label:"i18n_target_node_ids"
			,ignore:function(widget,sourceType){
				return widget.metadata("parameters.contextMenuForWindow") || widget.metadata("isSubMenu");
			}	
			,readOnly:function(widget,sourceType){
				return widget.metadata("parameters.contextMenuForWindow") || widget.metadata("isSubMenu");
			}
			,parse:function(value){
				return [_window.body()];
			}
			,hidden:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
		})	
		,parentMenu:lang.mixin({},agile.TextMetadata,{
			label:"i18n_parent_menu"
			,ignore:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,readOnly:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,hidden:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
		})								
			
		,leftClickToOpen:lang.mixin({},agile.BooleanMetadata,{
			label:"i18n_left_click_to_open"
			,ignore:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,readOnly:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,hidden:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
		})
		,refocus:lang.mixin({},agile.BooleanMetadata,{
			label:"i18n_refocus"
			,ignore:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,readOnly:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
			,hidden:function(widget,sourceType){
				return widget.metadata("isSubMenu");
			}
		})		
		,isSubMenu:lang.mixin({},agile.BooleanMetadata,{_hidden:true,_ignore:true})
		,moveable:lang.mixin({},agile.BooleanMetadata,{_hidden:true,_ignore:true})
	})
	,visible:false
	,workspaceNode:null/*the dom node of workspace containing this menu*/
	,initDefaultMetadata:function(){
		this.metadata("moveable",true);
		//this.metadata("parameters.accelKey","");	
		this.metadata("parameters.parentMenu","");
		this.metadata("parameters.targetNodeIds",[]);
		this.metadata("parameters.leftClickToOpen",false);
		this.metadata("parameters.refocus",false);
		this.metadata("style.width","235px");
		this.metadata("style.height","150px");
		this.metadata("isSubMenu",false);
		this.metadata("dojoDeclaredClass","dijit.Menu");
	}
	,_getDelegatePrototype:function(){
		return dijit.Menu.prototype;
	}
	,constructor: function(){
		agile.requireX("dijit.Menu");					
	}
	,init:function(){
		//style.set(this.domNode,{width:this.metadata("style.width"),height:this.metadata("style.height")});
		array.forEach(this._getChildren(),function(child){
			child.metadata("style.width",this.metadata("style.width"));
		},this);
		
		this.showControlButtons();
	}
	,showControlButtons:function(child){
		if(child){
			style.set(this.removeButton,{display:"inline",position:"absolute",right:"5px"});						
			construct.place(this.removeButton,child.getToolbarAnchorNode(),"last");
			this.selectedChild = child;
		}else{
			style.set(this.removeButton,{display:"none"});	
			style.set(this.addButton,{display:"inline",position:"absolute"});						
			construct.place(this.addButton,this.getToolbarAnchorNode(),"last");
		}
	}
	,createChild:function(){			
		var child = new agile.dijit.MenuItem({iconClass:'dijitEditorIcon dijitEditorIconCopy',label:'Copy',accelKey:'Ctrl + C'});
		child.metadata("style.width",this.metadata("style.width"));
		return child;
	}
	,getResizableTargetContainer:function(){
		return this.domNode;		 
	}
[/@]
